package com.ra.landlord;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.Where;

import com.ra.system.Version;
import com.ra.util.Address;

/**
 * 房间信息表
 * 
 * @author Jerry.Feng Date: 2014-07-31
 */
@Entity
@Table(name = "ra_room")
@Where(clause = "data_status = 1")
public class SimpleRoom implements Version, LandlordOwner {

	private Integer id;
	
	private String no;
	
	private String name;
	
	// 此处房租和合约房租不一样，合约房租签订合约房租后就不会变，room里的房租可能递增
	private String rental;
	
	//描述几房几厅
	private Integer roomType; 
	
	// 冗余: Building.address
	private Address address;
	
	// TODO: 面积, 类型用BigDecimal?
	private BigDecimal area;
	
	// 房屋朝向
	private Integer orientation;
	
	// 照片序号，目前照片以数字排序存于固定的目录下
	private Integer pictureNo;
	
	// 租借状态(0:已出租；1：未出租；2：预定；3：转租；4：隐藏)
	private Integer rentState;
	
	// 房屋用途: 0：出租		1：商用
	private Integer purpose;
	
	// 冗余: BuildingFloor.building
	private Building building;
	
	private BuildingFloor buildingFloor;
	
	// 标配的标志， 用于搜房： 比方有无宽带，空调，洗手间等
	// room_config
	private Integer config;
	
	
	private LandlordOwnerUser landlordUser;
	
	//备注
	private String remark;
	
	// 创建时间
	private Date createTime;
	
	private Integer version;
	
	private Integer status;
	
	//@EmbeddedId
	@Id
	@GeneratedValue
	@Column(name = "room_id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "room_num")
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	@Column(name = "room_name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "rental")
	public String getRental() {
		return rental;
	}

	public void setRental(String rental) {
		this.rental = rental;
	}
	
	@ManyToOne(targetEntity=Address.class, fetch=FetchType.LAZY, optional=true, cascade=CascadeType.MERGE)
	@JoinColumn(name = "area_id")
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	@Column(name = "room_state")
	public Integer getRentState() {
		return rentState;
	}

	public void setRentState(Integer rentState) {
		this.rentState = rentState;
	}

	@Column(name = "room_funtion")
	public Integer getPurpose() {
		return purpose;
	}

	public void setPurpose(Integer purpose) {
		this.purpose = purpose;
	}

	@ManyToOne(targetEntity=Building.class, fetch=FetchType.LAZY, optional=false)
	@JoinColumn(name = "buildings_id")
	@Index(name="idx_ra_room_buildings_id")
	public Building getBuilding() {
		return building;
	}

	public void setBuilding(Building building) {
		this.building = building;
	}

	@Column(name = "room_area")
	public BigDecimal getArea() {
		return area;
	}

	public void setArea(BigDecimal area) {
		this.area = area;
	}
	
	@Column(name = "room_face")
	public Integer getOrientation() {
		return orientation;
	}

	public void setOrientation(Integer orientation) {
		this.orientation = orientation;
	}
	
	@Column(name = "pictures_id")
	public Integer getPictureNo() {
		return pictureNo;
	}

	public void setPictureNo(Integer pictureNo) {
		this.pictureNo = pictureNo;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "floor_id")
	public BuildingFloor getBuildingFloor() {
		return buildingFloor;
	}

	public void setBuildingFloor(BuildingFloor buildingFloor) {
		this.buildingFloor = buildingFloor;
	}

	@Column(name = "room_config")
	public Integer getConfig() {
		return config;
	}

	public void setConfig(Integer config) {
		this.config = config;
	}
		
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "createuserid")
	@Index(name="idx_ra_room_createuserid")
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}
	
	@Column(name = "version_id")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
	@Column(name = "data_status")
	@Index(name="idx_ra_room_creator_status",columnNames={"createuserid","data_status","buildings_id"})
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	
	@Column(name = "room_type")
	public Integer getRoomType() {
		return roomType;
	}

	public void setRoomType(Integer roomType) {
		this.roomType = roomType;
	}
	
	
	@Column(name = "strRemark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
}
